package it.irondev.appturismo.service.impl;

import it.irondev.appturismo.dao.AccomodationsMapper;
import it.irondev.appturismo.dao.AccomodationtypeMapper;
import it.irondev.appturismo.dao.example.AccomodationsExample;
import it.irondev.appturismo.dao.example.AccomodationsExample.Criteria;
import it.irondev.appturismo.entity.Accomodation;
import it.irondev.appturismo.entity.Accomodationtype;
import it.irondev.appturismo.filter.BaseFilter;
import it.irondev.appturismo.service.IAccomodationsService;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class AccomodationsServiceImpl implements IAccomodationsService {

	@Autowired
	AccomodationsMapper accomodationDao;
	
	@Autowired
	AccomodationtypeMapper accomodationTypeDao;
	
	
	public Accomodation getAccomodationById(Integer idAccomodation) {
		return accomodationDao.selectByPrimaryKey(idAccomodation);
	}

	public void addAccomodation(Accomodation accomodation) {
		accomodationDao.insert(accomodation);
	}

	
	public List<Accomodation> getAllAccomodations() {
		return accomodationDao.selectByExample(null);
	}

	public void updateAccomodation(Accomodation accomodation) {
		accomodationDao.updateByPrimaryKeySelective(accomodation);
	}

	public void deleteAccomodation(Integer idAccomodation) {
		accomodationDao.deleteByPrimaryKey(idAccomodation);
	}

	public List<Accomodationtype> getAllAccomodationType() {
		return accomodationTypeDao.selectByExample(null);
	}

	public List<Accomodation> getAccomodationByFilter(BaseFilter filter) {
		AccomodationsExample example = null;
		if(filter!=null) {
			example = new AccomodationsExample();
			Criteria criteria = example.createCriteria();
			if(filter.getId()!=null)
				criteria.andIdaccomodationEqualTo(filter.getId());
			if(filter.getIdlanguage()!=null)
				criteria.andLanguageEqualTo(filter.getIdlanguage());
			example.or(criteria);
		}
			
		return accomodationDao.selectByExample(example);	
	}
	
	
}
